package com.yt.project.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yt.project.common.BaseResponse;
import com.yt.project.common.ResultUtils;
import com.yt.project.model.dto.douyin.DouyinDescQueryRequest;
import com.yt.project.model.dto.kuaishou.KuaishouDescQueryRequest;
import com.yt.project.model.dto.kuaishou.KuaishouQueryRequest;
import com.yt.project.model.entity.Kuaishou;
import com.yt.project.model.vo.DescVO;
import com.yt.project.model.vo.KuaishouVO;
import com.yt.project.model.vo.TagDistVO;
import com.yt.project.service.KuaishouService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/kuaishou")
public class KuaishouController {

    @Resource
    private KuaishouService kuaishouService;

    /**
     * 获取哔哩哔哩信息列表
     * @return
     */
    @PostMapping("/list")
    public BaseResponse<List<Kuaishou>> getKuaishouList() {
        List<Kuaishou> list = kuaishouService.list();
        return ResultUtils.success(list);
    }

    /**
     * 分页获取
     * @param kuaishouQueryRequest
     * @return
     */
    @PostMapping("/page")
    public BaseResponse<Page<KuaishouVO>> getKuaishouPage(@RequestBody KuaishouQueryRequest kuaishouQueryRequest) {
        long current = 1;
        long pageSize = 10;
        if (kuaishouQueryRequest != null) {
            current = kuaishouQueryRequest.getCurrent();
            pageSize = kuaishouQueryRequest.getPageSize();
        }
        Kuaishou kuaishouQuery = new Kuaishou();
        BeanUtils.copyProperties(kuaishouQueryRequest, kuaishouQuery);
        QueryWrapper<Kuaishou> kuaishouQueryWrapper = new QueryWrapper<>(kuaishouQuery);
        Page<KuaishouVO> kuaishouPage = kuaishouService.pageKuaishou(kuaishouQueryRequest);
        return ResultUtils.success(kuaishouPage);
    }


    @PostMapping("/desc")
    public BaseResponse<DescVO> getKuaishouDesc(@RequestBody KuaishouDescQueryRequest kuaishouDescQueryRequest) {
        DescVO descVO = kuaishouService.getDescById(kuaishouDescQueryRequest.getId());
        return ResultUtils.success(descVO);
    }


    @PostMapping("/dist/tags")
    public BaseResponse<List<TagDistVO>> getTagsDist(@RequestBody KuaishouDescQueryRequest kuaishouDescQueryRequest) {
        List<TagDistVO> tagDistVOS = kuaishouService.getTagsDist(kuaishouDescQueryRequest.getId());
        return ResultUtils.success(tagDistVOS);
    }
}
